<?php
include ('../pages/check_login.include.php');

include ('../classes/autoloading_pages.include.php');

if (!$logged) {
    header('Location: /eventijesolo/login/');
    exit();
}

$hm = new HTMLElementsManager();
$navigation = $hm->get_HTML_element_by_name('navigation');
$footer = $hm->get_HTML_element_by_name('footer');

define (ACTION, 'action');
define (ACTION_EDIT, 'edit');
define (ACTION_NEW, 'new');
define (ACTION_SAVE, 'save');
define (ACTION_DELETE, 'delete');
define (HTML_ID, 'name');

$through_controller = TRUE;
if (isset($_GET[ACTION])) {
    $hm = new HTMLElementsManager();
    if($_GET[ACTION] == ACTION_EDIT){
        if(isset($_GET[HTML_ID])) {
            $element = $hm->get_HTML_element_by_name($_GET['name']);
        } else {
            echo 'error';
            exit();
        }
    } else if ($_GET[ACTION] == ACTION_SAVE) {
        if (isset($_GET[HTML_ID])) {
            $element = $hm->get_HTML_element_by_name($_GET[HTML_ID]);
            $element->content = (isset($_POST['content'])) ? $_POST['content'] : '';
            $hm->update_HTML_element($element);
        } else {
            echo 'Errore';
            exit();
        }
        header('Location: /eventijesolo/');
        exit();
    }
} else {
    echo 'Nessuna azione definita: errore!';
    exit();
}

include ('html.view.php');
?>
